﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Wmi.Dfsr;


namespace dfsr_nrpe_nt
{
    class dfsr_nrpe_nt
    {
        const int OK = 0;
        const int Warning = 1;
        const int Critical = 2;
        const int Unknown = 3;

        //SERVER NAME
        //WARNING
        //CRITICAL

        static int Main(string[] args)
        {

            if (args.Length < 3)
            {
                Console.WriteLine("dfsr_nrpe_nt SERVER_NAME WARNING CRITICAL");
                return Unknown;
            }

            String argServerName    = args[0];
            int argWarning          = Convert.ToInt32(args[1]);
            int argCritical         = Convert.ToInt32(args[2]);

            Wmi.Connection wmiConnection  
                = new Wmi.Connection(argServerName, Wmi.WmiNamespace.Dfsr);

            Wmi.Dfsr.ReplicatedFolderInfo replicatedFolderInfo 
                = new Wmi.Dfsr.ReplicatedFolderInfo(wmiConnection.ManagementScope);

            UInt32 outboundBacklogCount = replicatedFolderInfo.GetOutboundBacklogFileCount();

            if (outboundBacklogCount < argWarning)
            {
                Console.WriteLine("Current Backlog: {0}", outboundBacklogCount);
                return OK;
            }
            else if (outboundBacklogCount > argCritical)
            {
                Console.WriteLine("Current Backlog: {0}", outboundBacklogCount);
                return Critical;
            }
            else
            {
                Console.WriteLine("Current Backlog: {0}", outboundBacklogCount);
                return Warning;
            }


            return OK;
        }
    }
}
